﻿<UserControl x:Class="MVVM.Client.Views.AvailableQuestionnaireTemplatesListView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"  
    xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
    xmlns:vm="clr-namespace:MVVM.Client.ViewModels"
    xmlns:model="clr-namespace:MVVM.Questionnaires.Model;assembly=MVVM.Questionnaires"
    xmlns:views="clr-namespace:MVVM.Client.Views"
    xmlns:Behaviors="clr-namespace:MVVM.Client.Infrastructure.Behaviors" xmlns:GuidanceTools="clr-namespace:Microsoft.Practices.Prism.GuidanceTools;assembly=Microsoft.Practices.Prism.GuidanceTools" mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400" 
    d:DataContext="{d:DesignData /SampleData/AvailableQuestionnaireTemplatesListViewModelSampleData.xaml}">

    <Border BorderBrush="{StaticResource PrimaryBrush}" BorderThickness="2" Margin="2,2,2,10">
        <Grid x:Name="LayoutRoot" Background="White">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <ListBox x:Name="QuestionnaireTemplates" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                     ItemsSource="{Binding QuestionnaireTemplates}"
                     SelectedItem="{Binding QuestionnaireTemplateSummary.CurrentlySelectedQuestionnaireTemplate, Mode=TwoWay}"
                     Grid.Row="0">

                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                    </Style>
                </ListBox.ItemContainerStyle>

                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Border BorderThickness="2" BorderBrush="#FF4E80C4" Background="#FFECECEF" CornerRadius="3">
                            <Grid HorizontalAlignment="Stretch" Margin="2">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition />
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>

                                <TextBlock Grid.Column="0" Text="{Binding Title}" HorizontalAlignment="Stretch"/>

                                <!-- 
                                Binds the command provided by the AvailableQuestionnaireTemplatesListViewModel from the
                                DataTemplate by binding through the DataContext of an element outside the DataTemplate,
                                while binding to the local data context for the command parameter
                                -->
                                <Button Grid.Column="1" Width="85" Height="23"
                                    Command="{Binding DataContext.TakeSurveyCommand, ElementName=QuestionnaireTemplates}"
                                    CommandParameter="{Binding}">
                                    Take Survey
                                </Button>
                                <GuidanceTools:InfoTipToggleButton Grid.Column="2">
                                    <StackPanel MaxWidth="400">
                                        <TextBlock TextWrapping="Wrap">This button binds the command provided by the AvailableQuestionnaireTemplatesListViewModel from the
                                DataTemplate by binding through the DataContext of an element outside the DataTemplate,
                                while binding to the local data context for the command parameter.</TextBlock>
                                    </StackPanel>
                                </GuidanceTools:InfoTipToggleButton>
                            </Grid>
                        </Border>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

            <views:QuestionnaireTemplateSummaryView DataContext="{Binding QuestionnaireTemplateSummary}" Grid.Row="1"/>
        </Grid>
    </Border>
</UserControl>
